import { defineStore } from "pinia";
export const directives = defineStore("directives", {
  state: () => ({
    directivesList: [],
  }),
  actions: {
    getList(data) {
      data.$http.post("/sys/menu/user/has/menu").then((rs) => {
        if (rs.data) {
          this.menusFor(rs.data);
        }
      });
    },
    menusFor(data) {
      if (data) {
        data.forEach((res) => {
          if (res.menuType == 2) {
            this.directivesList.push(res.id);
          }
          if (res.children.length - 0 > 0) {
            this.menusFor(res.children);
          }
        });
        localStorage.setItem("btnPermission", this.directivesList);
        return this.directivesList;
      }
    },
  },
});
